package controller;

import Utils.dateUtil;
import com.smart.domain.Express;
import com.smart.domain.User;
import com.smart.infer.expressPieceInt;
import com.smart.infer.userPubInt;
import com.smart.service.expressPieceService;
import com.smart.service.selectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName expressPieceController
 * @Description 揽件 将信息显示在个人中心我的揽件中  揽件人积分+10，被揽件方积分-10 点击揽件显示订单详细信息
 * @Author wangqian
 * @Date 2019/3/31 21:16
 **/

@Controller
public class expressPieceController {
    @Autowired
    private expressPieceService eps;
    @Autowired
    private selectService seService;
    @Autowired
    private userPubInt mapper;
    @Autowired
    private expressPieceInt ep;

    @RequestMapping("/expressPiece.html")//点击揽件操作
    public ModelAndView expressPiece(HttpServletRequest request,@RequestParam(value = "number", required = false, defaultValue = "默认值") String e_number){
        String userid = (String)request.getSession().getAttribute("userid");//获得当前登录用户名
//        System.out.println("------------"+userid);
        User user=eps.selectPhoneByUserid(userid);
        String phonenum=user.getPhonenumber();
        String name=user.getUsername();
        dateUtil date=new dateUtil();//获得系统当前时间
        String leadtime=date.date();
//        System.out.println("快递号"+e_number);
        eps.expressPiece(e_number);
        eps.udateScoreUp(userid);//增加揽件人积分
        eps.updateExpressPiece(e_number,name,phonenum,userid,leadtime);//更新揽件人姓名电话用户名 揽件时间
        Express express=eps.selectExpressByEnum(e_number);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("detailExpress",express);
        modelAndView.setViewName("leadExpressSuccess");
        return modelAndView;
    }

    @RequestMapping("/selectExpressByAddress.html")//根据宿舍楼查询快递
    public ModelAndView selectEBA(HttpServletRequest request) throws UnsupportedEncodingException {
        request.setCharacterEncoding("UTF-8");
        String userid = (String)request.getSession().getAttribute("userid");//获得当前登录用户名
        String e_esc=request.getParameter("esc");
        String address=request.getParameter("e_address");
        List listExpress=new ArrayList();
        if(e_esc.equals("菜鸟驿站")){
            List<Express> list= ep.selectExpressByAddress(address,"中通",userid);
            List<Express> list2= ep.selectExpressByAddress(address,"圆通",userid);
            List<Express> list3= ep.selectExpressByAddress(address,"韵达",userid);
            List<Express> list4= ep.selectExpressByAddress(address,"天天",userid);
            listExpress.addAll(list);listExpress.addAll(list2);
            listExpress.addAll(list3);listExpress.addAll(list4);
        }else{
            listExpress=ep.selectExpressByAddress(address,e_esc,userid);

        }
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("name",e_esc);
        modelAndView.addObject("address",address);
        modelAndView.addObject("list",listExpress);
        modelAndView.setViewName("leadExpress");
        return modelAndView;
    }
}

